home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 342_01.zip / DIOFNC04.C < prev    next >
C/C++ Source or Header  |  1993-04-03  |  3KB  |  83 lines

  1. /*-
  2.  *  ----------------------------------------------------------------------
  3.  *  File        :   DIOFNC04.C
  4.  *  Creator     :   Blake Miller
  5.  *  Version     :   01.01.00        February 1991
  6.  *  Language    :   Microsoft C     Version 5.1
  7.  *  Purpose     :   Intel 8255 Compatible Digital IO Functions
  8.  *                  Bit Get Function
  9.  *  ----------------------------------------------------------------------
  10.  *  Revision History:
  11.  *  022891 BVM  :   Change int to short.
  12.  *  070490 BVM  :   Creation
  13.  *  ----------------------------------------------------------------------
  14.  */
  15.  
  16. #define     DIOFNC04_C_DEFINED  1
  17. #include    "DIOLIB.H"
  18. #undef      DIOFNC04_C_DEFINED
  19.  
  20. void dio_bitget (DIODAT *data, short bit, short *state);
  21.  
  22. /*- DIO : Bit Get ----------------------------**
  23.  *  Read one of the bits in the 8255.
  24.  *  A state of 1 indicates a set bit and a state of 0
  25.  *  indicates a clear bit.
  26.  *  The bit number should be from 0 - 23 as follows:
  27.  *   0 = Port A Bit 0;   7 = Port A Bit 7
  28.  *   8 = Port B Bit 0;  15 = Port B Bit 7
  29.  *  16 = Port C Bit 0;  23 = Port C Bit 7
  30.  *  Passed:
  31.  *      pointer :   DIODAT
  32.  *      short   :   bit number
  33.  *      pointer :   short :   state : 1 = SET, 0 = CLEAR
  34.  *  Returns:
  35.  *      nothing
  36.  *      Loads stat with approrpiate error code.
  37.  *      Loads state with 0 or 1.
  38.  */
  39. void dio_bitget (DIODAT *data, short bit, short *state)
  40.     {
  41.     short           port;   /* port number  */
  42.     unsigned char   ival;   /* in value     */
  43.  
  44.     /*  Make sure the bit requested is valid.
  45.      *  Three ports of 8 bits each = 24 total bits.
  46.      *  This will also validate the port number used later.
  47.      */
  48.     if ( (bit < 0) || (bit > 23) ){
  49.         data->stat = DIO_ST_BB;
  50.         return;
  51.         }
  52.  
  53.     /*  The bit number should have zero offset.
  54.      *  This is useful for lining up the port with integer
  55.      *  divide and it is also used for left shifting to
  56.      *  create a mask.
  57.      *  Get port number by doing integer division.  The port
  58.      *  number should end up as 0, 1, or 2, corresponding to
  59.      *  PORT A, PORT B, and PORT C respectively.
  60.      *  Then do modulo 8 to get the corrsponding bit
  61.      *  number to be used in the particular byte.  This
  62.      *  value will end up being 0 - 7.
  63.      */
  64.     port = ( bit / 8);      /* port number (0 - 2)          */
  65.     bit = bit % 8;          /* modulo to get the bit number */
  66.  
  67.     /*  Input data.
  68.      *  Right shift data to line it up with the proper bit.
  69.      */
  70.     dio_bget ( data->base + port, &ival );
  71.     ival = ival >> bit;         /* left shift input data    */
  72.     ival = ival & 0x01;         /* mask out upper bits      */
  73.     *state = (short) ival;      /* load value               */
  74.  
  75.     data->stat = DIO_ST_OK;
  76.     }
  77.  
  78. /*-
  79.  *  ----------------------------------------------------------------------
  80.  *  END DIOFNC04.C Source File
  81.  *  ----------------------------------------------------------------------
  82.  */
  83.